﻿define(function (require) {
    require('model/AppFunc');
    var AppFuncView = require('view/AppFuncView');
    var utility = require('ezdesk/utility/utility.js');
    
    return Backbone.View.extend({
        el: $('#app-list'),
        events: {
        },

        initialize: function () {
            _.bindAll(this, 'render', 'addOneAppFunc');
            this.model.view = this;
        },

        render: function () {
            this.model.each(this.addOneAppFunc);
            $(this.el).find('a.ezlink').each(function (index, item) {
                utility.HandleATag(item);
            });

            $(this.el).fadeIn();
            return this;
        },

        addOneAppFunc: function (appFunc, index) {
            var appFuncView = new AppFuncView({ model: new AppFunc(appFunc) });
            $(this.el).append(appFuncView.render().el);
        },

        clear: function () {
            $(this.el).empty().hide();
        }
    });
});